10/25/2005: becomes a writer too
10/26/2005: received documention from CompeGPS team
added fatals for "G" and "U" if not WGS84 and lat/lon
+ 08/13/2006: switch to gbfile api
*/
/*
#define SHORT_NAME_LENGTH 16
-static FILE *fin, *fout;
-static char *fin_name, *fout_name;
+static gbfile *fin, *fout;
static int target_index, curr_index;
static int track_info_flag;
static short_handle sh;
static void
compegps_rd_init(const char *fname)
{
- fin_name = (char *)fname;
- fin = xfopen(fname, "rb", MYNAME);
+ fin = gbfopen(fname, "rb", MYNAME);
}
static void
compegps_rd_deinit(void)
{
- fclose(fin);
+ gbfclose(fin);
}
static void
compegps_data_read(void)
{
- textfile_t *tin;
char *buff;
int line = 0;
waypoint *wpt = NULL;
route_head *route = NULL;
route_head *track = NULL;
- tin = textfile_init(fin);
- while ((buff = textfile_read(tin)))
+ while ((buff = gbfgetstr(fin)))
{
char *cin = buff;
char *ctail, *cx;
break;
}
}
- textfile_done(tin);
}
/* ----------------------------------------------------------- */
name = (snlen > 0) ? mkshort_from_wpt(sh, wpt) : csv_stringclean(wpt->shortname, " ");
- fprintf(fout, "W %s A ", name);
- fprintf(fout, "%.10f%c%c ",
+ gbfprintf(fout, "W %s A ", name);
+ gbfprintf(fout, "%.10f%c%c ",
fabs(wpt->latitude), 0xBA, (wpt->latitude >= 0) ? 'N' : 'S');
- fprintf(fout, "%.10f%c%c ",
+ gbfprintf(fout, "%.10f%c%c ",
fabs(wpt->longitude), 0xBA, (wpt->longitude >= 0) ? 'E' : 'W');
- fprintf(fout, "27-MAR-62 00:00:00 %.6f",
+ gbfprintf(fout, "27-MAR-62 00:00:00 %.6f",
(wpt->altitude != unknown_alt) ? wpt->altitude : 0.0);
if (wpt->description != NULL)
- fprintf(fout, " %s", wpt->description);
- fprintf(fout, "\n");
+ gbfprintf(fout, " %s", wpt->description);
+ gbfprintf(fout, "\n");
if ((wpt->icon_descr != NULL) || (wpt->proximity > 0.0) || \
(option_icon != NULL))
if (wpt->icon_descr != NULL) icon = (char *) wpt->icon_descr;
- fprintf(fout, "w %s,0,0.0,16777215,255,1,7,,%.1f\n",
+ gbfprintf(fout, "w %s,0,0.0,16777215,255,1,7,,%.1f\n",
(icon != NULL) ? icon : "Waypoint",
(wpt->proximity > 0.0f) ? wpt->proximity : 0.0);
}
name = csv_stringclean(name, ",");
else
name = xstrdup(" ");
- fprintf(fout, "R 16711680,%s,1,-1\n", name);
+ gbfprintf(fout, "R 16711680,%s,1,-1\n", name);
xfree(name);
}
strupper(buff);
}
- fprintf(fout, "T A %.10f%c%c %.10f%c%c ",
+ gbfprintf(fout, "T A %.10f%c%c %.10f%c%c ",
fabs(wpt->latitude), 0xBA, (wpt->latitude >= 0) ? 'N' : 'S',
fabs(wpt->longitude), 0xBA, (wpt->longitude >= 0) ? 'E' : 'W');
- fprintf(fout, "%s s %.1f %.1f %.1f %.1f %d ",
+ gbfprintf(fout, "%s s %.1f %.1f %.1f %.1f %d ",
buff,
wpt->altitude,
0.0,
0.0,
0.0,
0);
- fprintf(fout, "%.1f %.1f %.1f %.1f %.1f\n",
+ gbfprintf(fout, "%.1f %.1f %.1f %.1f %.1f\n",
-1000.0,
-1.0,
-1.0,
char *name;
name = csv_stringclean(curr_track->rte_name, "|");
- fprintf(fout, "t 4294967295|%s|-1|-1\n", name);
+ gbfprintf(fout, "t 4294967295|%s|-1|-1\n", name);
xfree(name);
}
}
{
curr_index = 0;
-// fprintf(fout, "L +02:00:00\n");
+// gbfprintf(fout, "L +02:00:00\n");
track_disp_all(write_track_hdr_cb, NULL, write_trkpt_cb);
- fprintf(fout, "F 1234\n");
+ gbfprintf(fout, "F 1234\n");
}
static void
static void
compegps_wr_init(const char *fname)
{
- fout_name = (char *)fname;
- fout = xfopen(fname, "w", MYNAME);
+ fout = gbfopen(fname, "w", MYNAME);
sh = mkshort_new_handle();
}
compegps_wr_deinit(void)
{
mkshort_del_handle(&sh);
- fclose(fout);
+ gbfclose(fout);
}
static void
{
/* because of different file extensions we can only write one GPS data type at time */
- fprintf(fout, "G WGS 84\n");
- fprintf(fout, "U 1\n");
+ gbfprintf(fout, "G WGS 84\n");
+ gbfprintf(fout, "U 1\n");
/* process options */
unsigned int track_header_written:1;
} gtxt_flags_t;
-static FILE *fin, *fout;
+static gbfile *fin, *fout;
static route_head *current_trk, *current_rte;
static int waypoints;
static int routepoints;
deg++;
min = 0;
}
- fprintf(fout, "%c%d %0*.*f ", lat < 0.0 ? 'S' : 'N', deg, precision + 3, precision, min);
+ gbfprintf(fout, "%c%d %0*.*f ", lat < 0.0 ? 'S' : 'N', deg, precision + 3, precision, min);
deg = fabs(lon);
min = (double)60.0 * (fabs(lon) - deg);
deg++;
min = 0;
}
- fprintf(fout, "%c%d %0*.*f\t", lon < 0.0 ? 'W' : 'E', deg, precision + 3, precision, min);
+ gbfprintf(fout, "%c%d %0*.*f\t", lon < 0.0 ? 'W' : 'E', deg, precision + 3, precision, min);
}
static void
if (time_only) {
tm = *gmtime(&time);
snprintf(tbuf, sizeof(tbuf), "%d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
- fprintf(fout, "%s", tbuf);
+ gbfprintf(fout, "%s", tbuf);
}
else if (time != 0) {
if (gtxt_flags.utc) {
else
tm = *localtime(&time);
strftime(tbuf, sizeof(tbuf), date_time_format, &tm);
- fprintf(fout, "%s ", tbuf);
+ gbfprintf(fout, "%s ", tbuf);
}
- fprintf(fout, "\t");
+ gbfprintf(fout, "\t");
}
static void
}
else c = NULL;
- fprintf(fout, "%s", (count++ > 0) ? "," : "");
+ gbfprintf(fout, "%s", (count++ > 0) ? "," : "");
if (c == NULL)
- fprintf(fout, "Category %d", i+1);
-// fprintf(fout, "%s", gps_categories[i]);
+ gbfprintf(fout, "Category %d", i+1);
+// gbfprintf(fout, "%s", gps_categories[i]);
else
- fprintf(fout, "%s", c);
+ gbfprintf(fout, "%s", c);
}
categories = categories >> 1;
if (course >= 360) {
course -= 360;
}
- cet_fprintf(fout, &cet_cs_vec_cp1252, "%d%c true", course, 0xB0);
+ cet_gbfprintf(fout, &cet_cs_vec_cp1252, "%d%c true", course, 0xB0);
}
}
dist = METERS_TO_FEET(dist);
if ((dist < 5280) || no_scale)
- fprintf(fout, "%.f ft", dist);
+ gbfprintf(fout, "%.f ft", dist);
else {
dist = METERS_TO_MILES(distance);
if (dist < (double)100)
- fprintf(fout, "%.1f mi", dist);
+ gbfprintf(fout, "%.1f mi", dist);
else
- fprintf(fout, "%d mi", si_round(dist));
+ gbfprintf(fout, "%d mi", si_round(dist));
}
}
else
{
if ((dist < 1000) || no_scale)
- fprintf(fout, "%.f m", dist);
+ gbfprintf(fout, "%.f m", dist);
else {
dist = dist / (double)1000.0;
if (dist < (double)100)
- fprintf(fout, "%.1f km", dist);
+ gbfprintf(fout, "%.1f km", dist);
else
- fprintf(fout, "%d km", si_round(dist));
+ gbfprintf(fout, "%d km", si_round(dist));
}
}
- if (with_tab) fprintf(fout, "\t");
+ if (with_tab) gbfprintf(fout, "\t");
}
static void
int ispeed = si_round(speed);
if (speed < (double)0.01)
- fprintf(fout, "0 %s", unit);
+ gbfprintf(fout, "0 %s", unit);
else if (ispeed < 2)
- fprintf(fout, "%.1f %s", speed, unit);
+ gbfprintf(fout, "%.1f %s", speed, unit);
else
- fprintf(fout, "%d %s", ispeed, unit);
+ gbfprintf(fout, "%d %s", ispeed, unit);
}
else
- fprintf(fout, "0 %s", unit);
- fprintf(fout, "\t");
+ gbfprintf(fout, "0 %s", unit);
+ gbfprintf(fout, "\t");
}
static void
*c = ' ';
}
}
- fprintf(fout, fmt, buff);
+ gbfprintf(fout, fmt, buff);
xfree(buff);
}
else
wpt_type = gt_waypt_class_names[0];
- fprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? wpt->shortname : "");
+ gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? wpt->shortname : "");
if (wpt_class <= gt_waypt_class_airport_ndb) {
char *temp = wpt->notes;
if (temp == NULL) {
print_string("%s\t", temp);
}
else
- fprintf(fout, "\t");
- fprintf(fout, "%s\t", wpt_type);
+ gbfprintf(fout, "\t");
+ gbfprintf(fout, "%s\t", wpt_type);
print_position(wpt);
if IS_VALID_ALT(wpt->altitude)
print_distance(wpt->altitude, 1, 0);
- fprintf(fout, "\t");
+ gbfprintf(fout, "\t");
x = GMSD_GET(depth, unknown_alt);
if (x != unknown_alt)
print_distance(x, 1, 0);
- fprintf(fout, "\t");
+ gbfprintf(fout, "\t");
x = GMSD_GET(proximity, unknown_alt);
if (x != unknown_alt)
print_distance(x, 0, 0);
- fprintf(fout, "\t");
+ gbfprintf(fout, "\t");
x = GMSD_GET(temperature, unknown_alt);
if (x != unknown_alt) {
if (gtxt_flags.celsius)
- fprintf(fout, "%.f C", x);
+ gbfprintf(fout, "%.f C", x);
else
- fprintf(fout, "%.f F", (x * 1.8) + 32);
+ gbfprintf(fout, "%.f F", (x * 1.8) + 32);
}
- fprintf(fout, "\t%s\t", dspl_mode);
+ gbfprintf(fout, "\t%s\t", dspl_mode);
- fprintf(fout, "Unknown\t"); /* Color is fixed: Unknown */
+ gbfprintf(fout, "Unknown\t"); /* Color is fixed: Unknown */
icon = GMSD_GET(icon, -1);
if (icon == -1) {
print_string("%s\t", wpt->url ? wpt->url : "");
print_categories(GMSD_GET(category, 0));
- fprintf(fout, "\r\n");
+ gbfprintf(fout, "\r\n");
}
static void
if (!gtxt_flags.route_header_written) {
gtxt_flags.route_header_written = 1;
- fprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[route_header]);
+ gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[route_header]);
}
print_string("\r\nRoute\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
print_distance(cur_info->length, 0, 1);
print_course(cur_info->first_wpt, cur_info->last_wpt);
- fprintf(fout, "\t%d waypoints\t", cur_info->count);
+ gbfprintf(fout, "\t%d waypoints\t", cur_info->count);
print_string("%s\r\n", rte->rte_url ? rte->rte_url : "");
- fprintf(fout, "\r\nHeader\t%s\r\n\r\n", headers[rtept_header]);
+ gbfprintf(fout, "\r\nHeader\t%s\r\n\r\n", headers[rtept_header]);
}
static void
{
waypoint *prev = cur_info->prev_wpt;
- fprintf(fout, "Route Waypoint\t");
- fprintf(fout, "%s\t", wpt->shortname);
+ gbfprintf(fout, "Route Waypoint\t");
+ gbfprintf(fout, "%s\t", wpt->shortname);
if (prev != NULL)
{
else
print_distance(0, 1, 0);
- fprintf(fout, "\r\n");
+ gbfprintf(fout, "\r\n");
cur_info->prev_wpt = (waypoint *)wpt;
}
if (!gtxt_flags.track_header_written) {
gtxt_flags.track_header_written = 1;
- fprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[track_header]);
+ gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[track_header]);
}
print_string("\r\nTrack\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
print_distance(cur_info->length, 0, 1);
print_speed(&cur_info->length, &cur_info->time);
print_string("%s", (track->rte_url != NULL) ? track->rte_url : "");
- fprintf(fout, "\r\n\r\nHeader\t%s\r\n\r\n", headers[trkpt_header]);
+ gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n\r\n", headers[trkpt_header]);
}
static void
time_t delta;
double dist;
- fprintf(fout, "Trackpoint\t");
+ gbfprintf(fout, "Trackpoint\t");
print_position(wpt);
print_date_and_time(wpt->creation_time, 0);
if IS_VALID_ALT(wpt->altitude)
print_distance(wpt->altitude, 1, 0);
- fprintf(fout, "\t0.0 %s", (gtxt_flags.metric) ? "m" : "ft");
+ gbfprintf(fout, "\t0.0 %s", (gtxt_flags.metric) ? "m" : "ft");
if (prev != NULL) {
- fprintf(fout, "\t");
+ gbfprintf(fout, "\t");
delta = wpt->creation_time - prev->creation_time;
dist = distance(prev->latitude, prev->longitude, wpt->latitude, wpt->longitude);
print_distance(dist, 0, 1);
print_speed(&dist, &delta);
print_course(prev, wpt);
}
- fprintf(fout, "\r\n");
+ gbfprintf(fout, "\r\n");
cur_info->prev_wpt = (waypoint *)wpt;
}
{
memset(>xt_flags, 0, sizeof(gtxt_flags));
- fout = xfopen(fname, "wb", MYNAME);
+ fout = gbfopen(fname, "wb", MYNAME);
grid_index = 1;
gtxt_flags.metric = (toupper(*get_option_val(opt_dist, "m")) == 'M');
static void
garmin_txt_wr_deinit(void)
{
- fclose(fout);
+ gbfclose(fout);
xfree(date_time_format);
}
static void
garmin_txt_write(void)
{
- cet_fprintf(fout, &cet_cs_vec_cp1252, "Grid\tLat/Lon hddd%cmm.mmm'\r\n", 0xB0);
- fprintf(fout, "Datum\t%s\r\n\r\n", datum_str);
+ cet_gbfprintf(fout, &cet_cs_vec_cp1252, "Grid\tLat/Lon hddd%cmm.mmm'\r\n", 0xB0);
+ gbfprintf(fout, "Datum\t%s\r\n\r\n", datum_str);
waypoints = 0;
gtxt_flags.enum_waypoints = 1; /* enum all waypoints */
route_disp_all(NULL, NULL, enum_waypt_cb);
qsort(wpt_a, waypoints, sizeof(*wpt_a), sort_waypt_cb);
- fprintf(fout, "Header\t%s\r\n\r\n", headers[waypt_header]);
+ gbfprintf(fout, "Header\t%s\r\n\r\n", headers[waypt_header]);
for (i = 0; i < waypoints; i++)
{
waypoint *wpt = wpt_a[i];
{
memset(>xt_flags, 0, sizeof(gtxt_flags));
- fin = xfopen(fname, "rb", MYNAME);
+ fin = gbfopen(fname, "rb", MYNAME);
memset(&header_ct, 0, sizeof(header_ct));
datum_index = -1;
for (h = waypt_header; h <= unknown_header; h++) {
free_header(h);
}
- fclose(fin);
+ gbfclose(fin);
xfree(date_time_format);
}
garmin_txt_read(void)
{
char *buff;
- textfile_t *tin;
current_line = 0;
- tin = textfile_init(fin);
- while ((buff = textfile_read(tin))) {
+ while ((buff = gbfgetstr(fin))) {
char *cin;
current_line++;
/* flush pending data */
while (csv_lineparse(NULL, "\t", "", 0));
}
- textfile_done(tin);
}
ff_vecs_t garmin_txt_vecs = {
#include <stdio.h>
#include <stdlib.h>
-static FILE *fin;
-static FILE *fout;
+static gbfile *fin, *fout;
static route_head *track, *route;
static waypoint *wpt;
static void
stmwpp_rd_init(const char *fname)
{
- fin = xfopen(fname, "rb", MYNAME);
+ fin = gbfopen(fname, "rb", MYNAME);
track = NULL;
route = NULL;
wpt = NULL;
static void
stmwpp_rd_deinit(void)
{
- fclose(fin);
+ gbfclose(fin);
}
static void
stmwpp_data_read(void)
{
char *buff;
- textfile_t *tin;
-
- tin = textfile_init(fin);
what = STM_NOTHING;
- buff = textfile_read(tin);
+ buff = gbfgetstr(fin);
buff = (buff == NULL) ? "" : buff;
if (strncmp(buff, "Datum,WGS 84,WGS 84,", 20) != 0)
fatal(MYNAME ": Invalid GPS datum or not \"WaypointPlus\"\" file!\n");
- while ((buff = textfile_read(tin)))
+ while ((buff = gbfgetstr(fin)))
{
char *c;
int column = -1;
wpt = NULL;
}
}
- textfile_done(tin);
}
static void
stmwpp_rw_init(const char *fname)
{
- fout = xfopen(fname, "wb", MYNAME);
+ fout = gbfopen(fname, "wb", MYNAME);
}
static void
stmwpp_rw_deinit(void)
{
- fclose(fout);
+ gbfclose(fout);
}
static void
c = buff + snprintf(buff, sizeof(buff), "%3.7f", val);
while (*--c == '0') *c = '\0';
if (*c == '.') *c = '0';
- fprintf(fout, "%s,", buff);
+ gbfprintf(fout, "%s,", buff);
}
static void
{
case STM_WAYPT:
case STM_RTEPT:
- fprintf(fout, "WP,D,%s,", wpt->shortname);
+ gbfprintf(fout, "WP,D,%s,", wpt->shortname);
break;
case STM_TRKPT:
- fprintf(fout, "TP,D,");
+ gbfprintf(fout, "TP,D,");
break;
}
stmwpp_write_double(wpt->latitude);
stmwpp_write_double(wpt->longitude);
- fprintf(fout, "%s,%s", cdate, ctime);
+ gbfprintf(fout, "%s,%s", cdate, ctime);
switch(what)
{
case STM_WAYPT:
case STM_RTEPT:
- fprintf(fout, ".%02d", wpt->centiseconds);
+ gbfprintf(fout, ".%02d", wpt->centiseconds);
break;
case STM_TRKPT:
- fprintf(fout, ".%03d", wpt->centiseconds * 10);
+ gbfprintf(fout, ".%03d", wpt->centiseconds * 10);
break;
}
- fprintf(fout, ",\r\n");
+ gbfprintf(fout, ",\r\n");
}
static void
else
track_index = 1;
- fprintf(fout, "Datum,WGS 84,WGS 84,0,0,0,0,0\r\n");
+ gbfprintf(fout, "Datum,WGS 84,WGS 84,0,0,0,0,0\r\n");
switch(global_opts.objective)
{